package org.smr.ministore.micro.client;

import java.util.ArrayList;
import java.util.List;

import org.blade.utils.Pager;
import org.smr.ministore.entities.Authority;
import org.smr.ministore.entities.Role;
import org.smr.ministore.entities.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import feign.hystrix.FallbackFactory;

@Component
public class HystrixUserClientFactory implements FallbackFactory<FeignUserMicroServiceClient> {

    private static final Logger LOGGER = LoggerFactory.getLogger(HystrixUserClientFactory.class);

    @Override
    public FeignUserMicroServiceClient create(Throwable cause) {
        HystrixUserClientFactory.LOGGER.info("fallback; reason was: {}", cause.getMessage());

        return new UserFeignClientWithFactory() {

            @Override
            public User queryById( Long id ) {
                User entity = new User();
                entity.setId(-1L);
                return entity;
            }

            @Override
            public int batchSave( List< User> entities){
                return 0;
            }



            public int save(User entity){
                return 0;
            }

            public int updateById(User id){
                return 0;
            }

            public int deleteById(Long id){
                 return 0;
            }

            public Pager<User> paginate( User entity, Long pageSize, Long pageNum){
                Pager<User> pager = new Pager<User>();
                return pager;
            }

            @Override
            public User queryByUserName(String userName) {
                User entity = new User();
                entity.setId(-1L);
                return entity;
            }

            @Override
            public Long getCountByUserName(String userName) {
                return 0L;
            }

            @Override
            public List<Role> getRoleByUser(Long userId) {
                List<Role> list = new ArrayList<>();
                return list;
            }

            @Override
            public List<Authority> getAuthoritiesByUser(Long userId) {
                List<Authority> list = new ArrayList<>();
                return list;
            }

        };//Return end
    }
}